import { loc, wrong_reg } from 'sui';

const ck_ascii = (v, info) => {
    if (!v) {
        return info;
    }

    const tmp = v.trim();
    if (!tmp) {
        return info;
    }

    let r = wrong_reg(tmp, /[a-zA-Z0-9-_.[\]<>:/{}]+$/, loc("cmd_13"));
    if (r) {
        return r;
    }

    return null;
};

const ck_num = (v, info="") => {
    const num = parseInt(v, 10);
    if (isNaN(num)) {
        return info + loc("ckn0");
    }

    return null;
};

const pad_2 = (n) => n < 10 ? '0' + n : n;

const pad_3 = (n) => {
    if (n < 10) {
        return "00" + n;
    }

    if (n < 100) {
        return "0" + n;
    }

    return n;
};

export {pad_2, pad_3, ck_num, ck_ascii};
